package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import model.Paper;
import model.Review;


/**
 * This class is for choosing a review to veiw.
 * 
 * @author Greg Coleman
 * 
 */

public class ViewReview extends JFrame {

	private Paper my_paper;

	private List<Review> revs;

	private JList<Review> revList;

	private JButton btnConfirm;

	public ViewReview(Paper the_paper) {
		super();
		my_paper = the_paper;
		init();
		pack();
	}

	private void init() {	
		setPreferredSize(new Dimension(400,400));
		setLayout(new BorderLayout());

		btnConfirm = new JButton("Close");
		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane, BorderLayout.CENTER);

		revList = new JList(my_paper.getReviews().toArray());
		scrollPane.setViewportView(revList);
		revList.addMouseListener(new MouseListener() {

			@Override
			public void mouseClicked(MouseEvent e) {
				if (revList.getModel().getElementAt(revList.getSelectedIndex()) != null) {
					RevRead revRead = new RevRead(revList.getModel().getElementAt(revList.getSelectedIndex()));
					revRead.setDefaultCloseOperation(revRead.DISPOSE_ON_CLOSE);
					revRead.setVisible(true);
					revRead.setLocationRelativeTo(null);
				}
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub

			}

		});
		JLabel lblRevSel = new JLabel("Review List");
		lblRevSel.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblRevSel.setHorizontalAlignment(SwingConstants.CENTER);
		add(lblRevSel, BorderLayout.NORTH);

		btnConfirm.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {		
				dispose();
			}	
		});
		add(btnConfirm, BorderLayout.SOUTH);
	}
}
